package com.sfc.sdsr.server.commands;

import com.sfc.sdsr.common.model.Address;
import com.sfc.sdsr.server.ClientData;
import com.sfc.sdsr.server.dao.DaoFactory;

public class CreateAddress extends Command {

    private Address newAddress;
    
    public CreateAddress(ClientData clientData) {
        dao = DaoFactory.getDao();
        if (clientData.getOperationParameter() instanceof Address) {
            newAddress = (Address) clientData.getOperationParameter();
        } else {
            log.error("Can't create address. Client Data corrupted, no Address found to Create");
            shouldExecute = false;
            returnObject = null;
        }
    }

    @Override
    protected void execute() {
        log.info("Creating an address");
        returnObject = dao.createAddress(newAddress);
    }

}
